package com.yq.homework.day23;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/23 21:29
 */
public class Demo061 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入文件名:");
        String s = scanner.nextLine();
        FileOutputStream f1 =null;
        try {
            f1 = new FileOutputStream(s);
            while (true) {
                System.out.println("请输入文件的内容：");
                String s1 = scanner.nextLine();
                if ("end".equals(s1)){
                    break;
                }
                f1.write(s1.getBytes());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (f1!=null){
                try {
                    f1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
